package firing;

import game.Bullet;
import game.Enemy;
import game.Player;

import java.util.List;

/** Node that chooses children based on how recently the shooter has fired */ 
public class LastFiredBranch extends AbstractBinaryNode {

    private static final long serialVersionUID = -115663392541716681L;
    private int frameThreshold;
    
    public LastFiredBranch() {
	super();
	randomizeNode();
    }
    
    @Override
    public void calculate(List<Bullet> bullets, double angle, Enemy shooter, Player player) {
	if (shooter.getLastFired() < frameThreshold && left != null) {
	    left.calculate(bullets, angle, shooter, player);
	} else { if (right != null)
	    right.calculate(bullets, angle, shooter, player);
	}
    }

    @Override
    public void randomizeNode() {
	frameThreshold = (int) (Math.random() * 10 );
	
    }

    public String toString() {
	return ("LastFired: " + frameThreshold);
    }

    @Override
    public Node duplicate() {
	LastFiredBranch duplicate = new LastFiredBranch();
	duplicate.frameThreshold = frameThreshold;
	if (left != null) {
	    duplicate.left = left.duplicate();
	}
	if (right != null) {
	    duplicate.right = right.duplicate();
	}
	return duplicate;
    }
}
